#pragma once
#ifndef __Comm_HPP__
#define __Comm_HPP__
#include <iostream>
using namespace std;
#include <string>
#include <cerrno>
#include <cstring>
#include <sys/types.h>
#include <sys/stat.h>
#define Path "./fifo"
#define Mode 0666
#include <fcntl.h>
#include <unistd.h>

class FIFO
{
public:
    FIFO(const string &path)
        : _path(path)
    {
        umask(0);
        int n = mkfifo(_path.c_str(), Mode);
        if (n < 0)
        {
            cerr << "mkfifo failed " << "errno:" << errno << "strerrno:" << strerror(errno) << endl;
        }
        else
        {
            cout << "mkfifo success!" << endl;
        }
    }
    ~FIFO()
    {
        int n = unlink(_path.c_str()); // 删除文件
        if (n < 0)
        {
            cerr << "unlink failed " << "errno:" << errno << "strerrno:" << strerror(errno) << endl;
        }
        else
        {
            cout << "unlink success!" << endl;
        }
    }

private:
    string _path;
};

#endif